home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / test / test1.c < prev    next >
C/C++ Source or Header  |  1990-07-23  |  1KB  |  126 lines

  1. /* test 1 */
  2.  
  3. #include <signal.h>
  4. #include <stdio.h>
  5.  
  6. #define SIGNUM 10
  7. #define MAX_ERROR 4
  8.  
  9. int glov, gct;
  10. extern int errno;
  11. int errct;
  12. int subtest = 1;
  13.  
  14. main()
  15. {
  16.   int i;
  17.  
  18.   printf("Test  1 ");
  19.   fflush(stdout);        /* have to flush for child's benefit */
  20.  
  21.   for (i = 0; i < 15; i++) {
  22.     test10();
  23.     test11();
  24.   }
  25.   if (errct == 0)
  26.     printf("ok\n");
  27.   else
  28.     printf(" %d errors\n", errct);
  29.   exit(0);
  30. }
  31.  
  32. test10()
  33. {
  34.   int i, n, pid;
  35.  
  36.   n = 4;
  37.   for (i = 0; i < n; i++) {
  38.     if ((pid = fork())) {
  39.         if (pid < 0) {
  40.             printf("\nTest 1 fork failed\n");
  41.             exit(1);
  42.         }
  43.         parent();
  44.     } else
  45.         child(i);
  46.   }
  47. }
  48.  
  49. parent()
  50. {
  51.  
  52.   int n;
  53.  
  54.   n = getpid();
  55.   wait(&n);
  56. }
  57.  
  58. child(i)
  59. int i;
  60. {
  61.   int n;
  62.  
  63.   n = getpid();
  64.   exit(i);
  65. }
  66.  
  67. test11()
  68. {
  69.   int i, k, func();
  70.  
  71.   for (i = 0; i < 4; i++) {
  72.     glov = 0;
  73.     signal(SIGNUM, func);
  74.     if ((k = fork())) {
  75.         if (k < 0) {
  76.             printf("Test 1 fork failed\n");
  77.             exit(1);
  78.         }
  79.         parent1(k);
  80.     } else
  81.         child1(k);
  82.   }
  83. }
  84.  
  85.  
  86. parent1(childpid)
  87. int childpid;
  88. {
  89.  
  90.   int n;
  91.  
  92.   for (n = 0; n < 5000; n++);
  93.   while (kill(childpid, SIGNUM) < 0)    /* null statement */
  94.     ;
  95.   wait(&n);
  96. }
  97.  
  98. func()
  99. {
  100.   glov++;
  101.   gct++;
  102. }
  103.  
  104. child1(k)
  105. int k;
  106. {
  107.   while (glov == 0);
  108.   exit(gct);
  109. }
  110.  
  111.  
  112.  
  113. e(n)
  114. int n;
  115. {
  116.   int err_num = errno;        /* save errno in case printf clobbers it */
  117.  
  118.   printf("Subtest %d,  error %d  errno=%d  ", subtest, n, errno);
  119.   errno = err_num;        /* restore errno, just in case */
  120.   perror("");
  121.   if (errct++ > MAX_ERROR) {
  122.     printf("Too many errors; test aborted\n");
  123.     exit(1);
  124.   }
  125. }
  126.